var config = $.ajax({url: baseURL + 'sys/dict/init',async:false}).responseJSON;
$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'biz/balancetopup/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true, hidden: true },
			{ label: '订单号', name: 'orderNo', index: 'orderNo', width: 80},
			{ label: '头像', name: 'headImg', index: 'head_img', width: 50,
				formatter: function(value, options, row) {
					return "<img style='width: 50px; height: 50px;' class='img-circle' src='" + value + "'>";
				}
			},
			{ label: '会员ID', name: 'memberId', index: 'memberId', width: 50 },
			{ label: '手机号', name: 'mobile', index: 'mobile', width: 80,
				formatter: function(value, options, row) {
					return '<a href="#" onclick=showPayInfo("' + (row.realname || '') + '","' + (row.bankCardNumber || '') + '","' + (row.bankName || '') + '","' + (row.bankNameBranch || '') + '","' + (row.alipay || '') + '","' + row.alipayImg + '","' + (row.wechat || '') + '","' + row.wechatImg + '")>' + value + '</a>';
				}
			}, 			
			{ label: '金额', name: 'amount', index: 'amount', width: 80 },
			{ label: '类型', name: 'type', index: 'type', width: 50,
				formatter: function(value, options, row) {
					if (value == 0) {
						return '<span class="label label-success">充值</span>';
					} else if (value == 1) {
						return '<span class="label label-info">提现</span>';
					}
				}
			},
			{ label: '订单状态', name: 'status', index: 'status', width: 50,
				formatter: function(value, options, row) {
					if (value == 0) {
						return '<span class="label label-primary">提交至第三方支付</span>';
					} else if (value == 1) {
						return '<span class="label label-warning">待审核</span>';
					} else if (value == 2) {
						return '<span class="label label-success">成功</span>';
					} else if (value == 3) {
						return '<span class="label label-danger">失败</span>';
					} else if (value == 4) {
						return '<span class="label label-info">审核拒绝</span>';
					}
				}
			},
			{ label: '描述', name: 'description', index: 'description', width: 80 },
			{ label: '充提时间', name: 'createTime', index: 'create_time', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function() {
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        },
        loadComplete:function(xhr) {
        	vm.countDto = xhr.countDto;
        }
    });
});

function showPayInfo(realname, bankCardNumber ,bankName, bankNameBranch, alipay ,alipayImg, wechat ,wechatImg) {
	layer.open({
		  type: 1,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['550px', '700px'], //宽高
		  content: '<table class="table">' + 
			'<tr><td><b>真实姓名</b></td><td id="realname"></td><td><b>银行卡号</b></td><td id="bankCardNumber"></td></tr>' + 
			'<tr><td><b>银行</b></td><td id="bankName"></td><td><b>分行</b></td><td id="bankNameBranch"></td></tr>' + 
			'<tr><td><b>支付宝</b></td><td id="alipay"></td><td><b>支付宝二维码</b></td><td id="alipayImg"></td></tr>' + 
			'<tr><td><b>微信</b></td><td id="wechat"></td><td><b>微信二维码</b></td><td id="wechatImg"></td></tr>' + 
			'</table>',
		   success: function() {
			   $("#realname").text(realname);
			   $("#bankCardNumber").text(bankCardNumber);
			   $("#bankNameBranch").text(bankNameBranch);
			   $("#bankName").text(bankName);
			   $("#alipay").text(alipay);
			   $("#alipayImg").html("<img src='" + alipayImg + "' width=150/>");
			   $("#wechat").text(wechat);
			   $("#wechatImg").html("<img src='" + wechatImg + "' width=150/>");
		   }
	});
}

var vm = new Vue({
	el:'#rrapp',
	data:{
		q: {mobile: null, authStatus: "", startDate: null, endDate: null, type: "" },
		showList: true,
		title: null,
		balanceTopup: {},
		authStatus: config.authStatus,
		countDto: {sumOne: 0, sumTwo: 0}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function() {
			vm.showList = false;
			vm.title = "会员充值";
			vm.balanceTopup = {};
		},
		saveOrUpdate: function (event) {
			var url = "biz/balancetopup/save";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.balanceTopup),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				postData:vm.q,
                page:page
            }).trigger("reloadGrid");
		},
        changeStatus: function (type) {
        	
        	var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			confirm('您确定操作？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "biz/balancetopup/changeStauts",
                    dataType: "json",
				    data: $.param({ids:ids,type:type},true),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
        }
	}
});